from typing import Any

from aiogram import types
from aiogram_dialog import DialogManager, Window
from aiogram_dialog.widgets.kbd import Back, Cancel, ScrollingGroup, Select
from aiogram_dialog.widgets.text import Format

from app.bot.dialog.dialog_states import SelectProxySG
from app.bot.dialog.getters.sites import sites_getter
from app.bot.dialog.widgets import LocaleText


async def set_site_id(
    call: types.CallbackQuery, widget: Any, manager: DialogManager, site_id: str
):

    manager.dialog_data["site_id"] = site_id
    await manager.switch_to(SelectProxySG.select_period)


sites_window = Window(
    LocaleText("select-site"),
    ScrollingGroup(
        Select(
            Format("{item.name}"),
            "catselsel",
            lambda site: site.id,
            "sites",
            on_click=set_site_id,
        ),
        width=2,
        height=4,
        id="catsel",
    ),
    Back(LocaleText("back-btn")),
    Cancel(LocaleText("cancel-btn")),
    state=SelectProxySG.list_of_sites,
    getter=sites_getter,
)
